import axios from 'axios'

export default class UploadAdapter {
  constructor(loader) {
    this.loader = loader
  }
  upload() {
    return this.loader.file.then(
      file =>
        new Promise((resolve, reject) => {
          console.log(this.loader);
          const data = new FormData()
          data.append('upload', file)
          axios
            .post('http://localhost:1000/upload', data)
            .then(res => {
              console.log(res)
              this.loader.uploaded = true
              resolve({ default: res.data.url })
            })
            .catch(err => {
              reject(err)
            })
        })
    )
  }
  abort() {}
}
